package com.ykt.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期工具类
 *
 * @author: long.hua
 * @date: 2016-02-16 15:32
 * @since 1.0
 */
public class DateUtil {

    private final static SimpleDateFormat hm = new SimpleDateFormat("HH:mm");
    private final static SimpleDateFormat hms = new SimpleDateFormat("HH:mm:ss");
    private final static SimpleDateFormat ymd1 = new SimpleDateFormat("yyyyMMdd");
    private final static SimpleDateFormat ymd2 = new SimpleDateFormat("yyyy-MM-dd");
    private final static SimpleDateFormat ymdhms1 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    private final static SimpleDateFormat ymdhms2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String hm(Date date){
    	if(date == null){
            return null;
        }
    	return hm.format(date);
    }

    public static String hms(Date date){
    	if(date == null){
            return null;
        }
    	return hms.format(date);
    }

    /**yyyyMMdd*/
    public static String ymd1(Date date){
        if(date == null){
            return null;
        }
        return ymd1.format(date);
    }

    public static String ymd2(Date date){
        if(date == null){
            return null;
        }
        return ymd2.format(date);
    }

    /**yyyyMMddHHmmssSSS*/
    public static String ymdhms1(Date date){
        if(date == null){
            return null;
        }
        return ymdhms1.format(date);
    }

    /**yyyy-MM-dd HH:mm:ss*/
    public static String ymdhms2(Date date){
        if(date == null){
            return null;
        }
        return ymdhms2.format(date);
    }

    public static Date getYMD(int year, int month, int dayOfMonth){
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        return cal.getTime();
    }
}
